<!DOCTYPE html> 
<html lang="ja"> 
    <head> 
        <meta charset="utf-8"> 
        <title>Read As Text</title>
                
        <script type="text/javascript" src="http://tm-lib-js.googlecode.com/svn/trunk/src/tm-lib.js"></script>
        <script type="text/javascript">
            
            function read (element) {
                if (!element.files.length) return ;
                
                var file = element.files[0];
                if (!/^text\//.test(file.type)) return ;    // text/plain, text/html, ...
                
                var fr = new FileReader();
                fr.onload = function(){
                    document.getElementById("text").value = fr.result;
                };
                
                fr.readAsText(file);
            }
            
//            var text = "aaaaaaaaaaaaaaaaaaaaa"
//            window.location.href = 'data:application/octet-stream,'+encodeURIComponent(text);
        
        </script>
    </head>
    
    <body>
        
        <h1>Read As Text</h1>
        
        <input type="file" onchange="read(this);" />
        
        <hr />
        <textarea id="text" cols="80" rows="20" wrap="off"></textarea>
        
        <hr />
        <h2>参考リンク</h2>
        <a href="http://archiva.jp/web/javascript/tab-menu.html">http://archiva.jp/web/javascript/tab-menu.html</a>
        
    </body>
</html>

